/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.PurgeMessagesResponse;
/*     */ import com.zimbra.soap.admin.type.MailboxWithMailboxId;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PurgeMessages
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  58 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  60 */     Element mreq = request.getOptionalElement("mbox");
/*     */     String[] accounts;
/*  62 */     if (mreq != null) {
/*  63 */       String[] accounts = { mreq.getAttribute("id") };
/*     */       
/*     */ 
/*  66 */       Provisioning prov = Provisioning.getInstance();
/*  67 */       for (String acctId : accounts) {
/*  68 */         Account acct = prov.get(Key.AccountBy.id, acctId);
/*  69 */         if (acct == null)
/*  70 */           throw AccountServiceException.NO_SUCH_ACCOUNT(acctId);
/*  71 */         checkAccountRight(zsc, acct, Rights.Admin.R_purgeMessages);
/*     */       }
/*     */     }
/*     */     else
/*     */     {
/*  76 */       checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
/*     */       
/*  78 */       accounts = MailboxManager.getInstance().getAccountIds();
/*     */     }
/*     */     
/*  81 */     PurgeMessagesResponse purgeResponse = new PurgeMessagesResponse();
/*  82 */     for (int i = 0; i < accounts.length; i++) {
/*  83 */       Account account = Provisioning.getInstance().getAccountById(accounts[i]);
/*  84 */       if (account != null) {
/*     */         MailboxWithMailboxId mboxResp;
/*     */         MailboxWithMailboxId mboxResp;
/*  87 */         if (Provisioning.onLocalServer(account)) {
/*  88 */           Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/*  89 */           if (mbox == null)
/*     */             continue;
/*  91 */           mbox.purgeMessages(null);
/*  92 */           mboxResp = new MailboxWithMailboxId(mbox.getId(), account.getId(), Long.valueOf(mbox.getSize()));
/*     */         } else {
/*  94 */           Server server = account.getServer();
/*  95 */           if (server == null)
/*     */             continue;
/*  97 */           SoapProvisioning soapProvisioning = SoapProvisioning.getAdminInstance();
/*  98 */           mboxResp = soapProvisioning.purgeMessages(account);
/*  99 */           if (mboxResp == null)
/*     */             continue;
/* 101 */           mboxResp.setAccountId(account.getId());
/*     */         }
/* 103 */         purgeResponse.addMailbox(mboxResp);
/*     */       } }
/* 105 */     return JaxbUtil.jaxbToElement(purgeResponse);
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 110 */     relatedRights.add(Rights.Admin.R_purgeMessages);
/* 111 */     notes.add("If account ids are specified, needs effective " + Rights.Admin.R_purgeMessages.getName() + " right for each account.  " + "If account ids are not specified, the authed account has to be a system admin.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/PurgeMessages.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */